package com.sx.wechat.controller;

import com.sx.wechat.shiro.InformationAuthorizationInfo;
import com.sx.wechat.shiro.SecurityUserUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by lihao on 2018/3/21.
 */
@Controller
public class TeacherController extends BaseController{
    protected final transient Log logger = LogFactory.getLog(getClass());


    /***
     * 跳转到登录页面
     *
     * @return
     */
    @RequestMapping(value = "login",method = RequestMethod.GET)
    public String toLogin() {
        InformationAuthorizationInfo principal = SecurityUserUtils.getPrincipal();
        // 如果已经登录，则跳转到管理首页
        if(principal != null){
            return "redirect:/main" ;
        }
        return "sysLogin" ;
    }
    /***
     * 实现用户登录
     *
     * @param username
     * @param password
     * @return
     */
    @RequestMapping(value = "login",method = RequestMethod.POST)
    public String Login(String username, String password, Model model, HttpServletRequest request) {
        InformationAuthorizationInfo principal = SecurityUserUtils.getPrincipal();
        // 如果已经登录，则跳转到管理首页
        if(principal != null){
            return "redirect:/main" ;
        }
        return "sysLogin" ;
    }
    @RequestMapping("/main")
    public ModelAndView main(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView modelAndView=new ModelAndView("index");
        return modelAndView;
    }


}
